package com.myjar.excel.v2;

import com.myjar.excel.util.StringUtils;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

public class ErrorLogger<T> implements Logger<T> {

    private List<String> errorMsg = new LinkedList<>();
    private boolean allRight = true;
    private _Workbook workbook;

    public ErrorLogger(_Workbook workbook) {
        this.workbook = workbook;
    }

    @Override
    public void log(Throwable throwable, int row, int cell) {
        errorMsg.add(StringUtils.formatError(row, cell, throwable));
        allRight = false;
    }

    @Override
    public void writeTo(OutputStream outputStream) {
        workbook.writeTo(outputStream);
    }

    @Override
    public void setWorkbook(_Workbook workbook) {
        this.workbook = workbook;
    }

    @Override
    public Collection<String> error() {
        return errorMsg;
    }

    @Override
    public void push(T t) {
        // skip
    }

    @Override
    public Collection<T> poll() {
        return null;
    }

    @Override
    public boolean allRight() {
        return allRight;
    }

    @Override
    public void close() throws IOException {
        workbook.close();
    }
}
